﻿#region Usings
using System;
using System.Web.Mvc;

using BK.BlusinessLogic;
using BK.Repositories.Abstract;

using Resources;
#endregion

namespace BK.UI.Web.Controllers
{
    public class CurrenciesController : UserDependedController
    {
        private readonly CurrenciesBl _currenciesBl;

        public CurrenciesController(ICurrenciesRepository currenciesRepository)
        {
            _currenciesBl = new CurrenciesBl(currenciesRepository);
        }

        public ActionResult List()
        {
            return View("List", _currenciesBl.GetByUserId(User.Id));
        }

        public ActionResult Edit(int id)
        {
            return View("Create", _currenciesBl.GetById(id));
        }

        [HttpPost]
        public ActionResult Edit(Model.Currency currency)
        {
            return List();
        }

        public ActionResult Delete(int id)
        {
            try
            {
                _currenciesBl.Delete(id);
            }
            catch(Exception ex)
            {
                ModelState.AddModelError("", GridLocalization.ErrorDeleteCurrency);
            }
            return List();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Model.Currency currency)
        {
            currency.UserId = User.Id;
            _currenciesBl.Save(currency);
            return List();
        }

        [HttpPost]
        public ActionResult Save(Model.Currency currency)
        {
            return List();
        }
    }
}